package com.qf.routing;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

public class Publisher {

    @Test
    public void publish() throws Exception {
        //1. connection
        Connection connection = ConnectionUtil.getConnection();
        //2. channel
        Channel channel = connection.createChannel();

        //3. exchange
        channel.exchangeDeclare("routing_exchange", BuiltinExchangeType.DIRECT);
        //4. queue1
        channel.queueDeclare("routing_queue1",true,false,false,null);
        //5. queue2
        channel.queueDeclare("routing_queue2",true,false,false,null);

        //6. bind - exchange + queue1 ~ error
        channel.queueBind("routing_queue1","routing_exchange","ERROR");
        //7. bind - exchange + queue2 ~ info
        channel.queueBind("routing_queue2","routing_exchange","INFO");
        //8. bind - exchange + queue2 ~ error
        channel.queueBind("routing_queue2","routing_exchange","ERROR");
        //9. bind - exchange + queue2 ~ warning
        channel.queueBind("routing_queue2","routing_exchange","WARNING");

        //10. send msg
        channel.basicPublish("routing_exchange","ERROR",null,"errorMessage".getBytes());
        channel.basicPublish("routing_exchange","INFO",null,"infoMessage".getBytes());
    }
}
